package com.example.adtest

import android.content.Context
import com.anythink.banner.api.ATBannerView
import com.anythink.core.api.ATAdConst
import com.anythink.core.api.AdError
import com.anythink.interstitial.api.ATInterstitial
import com.anythink.nativead.api.ATNative
import com.anythink.nativead.api.ATNativeNetworkListener
import com.anythink.rewardvideo.api.ATRewardVideoAd
import com.anythink.splashad.api.ATSplashAd
import com.anythink.splashad.api.ATSplashAdListener

class AdManager {

    companion object {
        private val  spalshId = "b68abe70713122"
        private val bannerId = "b68abe709b876d"
        private val screenId = "b68abe707bfda9"
        private val nativeId = "b68abe70920f4d"
        private val rewardId = "b68abe708779ef"
        fun loadSplash(context: Context,adListener: ATSplashAdListener) : ATSplashAd{
            val ATSplashAd = ATSplashAd(context,spalshId,adListener)
            ATSplashAd.loadAd()
            return ATSplashAd
        }

        fun loadBanner(context: Context,width: Int,height: Int) : ATBannerView{
            val ATBannerAd = ATBannerView(context)
            ATBannerAd.setPlacementId(bannerId)
            val map = HashMap<String,Int>()
            map[ATAdConst.KEY.AD_WIDTH] = width
            map[ATAdConst.KEY.AD_HEIGHT] = height
            ATBannerAd.setLocalExtra(map as Map<String, Any>?)
            ATBannerAd.loadAd()
            map.clear()
            return ATBannerAd
        }

        fun loadScreen(context: Context): ATInterstitial{
            val atInterstitial = ATInterstitial(context, screenId)
            atInterstitial.load()
            return atInterstitial
        }

        fun loadNative(context: Context,listener: ATNativeNetworkListener,width: Int,height: Int): ATNative{
            val atNative = ATNative(context, nativeId, listener)
            val hashMap = HashMap<String, Any>()
            hashMap[ATAdConst.KEY.AD_WIDTH] = width
            hashMap[ATAdConst.KEY.AD_HEIGHT] = height
            atNative.setLocalExtra(hashMap)
            atNative.makeAdRequest()
            return atNative
        }

        fun loadReward(context: Context,): ATRewardVideoAd{
            val atRewardVideoAd = ATRewardVideoAd(context, rewardId)
            atRewardVideoAd.load()
            return atRewardVideoAd
        }
    }

}